home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / trackfld.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  160 lines

  1. #include "driver.h"
  2.  
  3.  
  4. #define TIMER_RATE (4096/4)
  5.  
  6.  
  7. struct VLM5030interface konami_vlm5030_interface =
  8. {
  9.     3580000,    /* master clock  */
  10.     255,        /* volume        */
  11.     4,         /* memory region  */
  12.     0,         /* memory size    */
  13.     0,         /* VCU            */
  14. };
  15.  
  16. struct SN76496interface konami_sn76496_interface =
  17. {
  18.     1,  /* 1 chip */
  19.     { 14318180/8 }, /*  1.7897725 Mhz */
  20.     { 0x2064 }
  21. };
  22.  
  23. struct DACinterface konami_dac_interface =
  24. {
  25.     1,
  26.     { 80 }
  27. };
  28.  
  29. struct ADPCMinterface hyprolyb_adpcm_interface =
  30. {
  31.     1,          /* 1 channel */
  32.     4000,       /* 4000Hz playback */
  33.     4,          /* memory region 4 */
  34.     0,          /* init function */
  35.     { 100 }
  36. };
  37.  
  38.  
  39. static int SN76496_latch;
  40.  
  41. /* The timer port on TnF and HyperSports sound hardware is derived from
  42.    a 14.318 mhz clock crystal which is passed  through a couple of 74ls393
  43.     ripple counters.
  44.     Various outputs of the ripper counters clock the various chips.
  45.     The Z80 uses 14.318 mhz / 4 (3.4mhz)
  46.     The SN chip uses 14.318 ,hz / 8 (1.7mhz)
  47.     And the timer is connected to 14.318 mhz / 4096
  48.     As we are using the Z80 clockrate as a base value we need to multiply
  49.     the no of cycles by 4 to undo the 14.318/4 operation
  50. */
  51.  
  52. READ_HANDLER( trackfld_sh_timer_r )
  53. {
  54.     int clock = cpu_gettotalcycles() / TIMER_RATE;
  55.  
  56.     return clock & 0xF;
  57. }
  58.  
  59. READ_HANDLER( trackfld_speech_r )
  60. {
  61.     return VLM5030_BSY() ? 0x10 : 0;
  62. }
  63.  
  64. static int last_addr = 0;
  65.  
  66. WRITE_HANDLER( trackfld_sound_w )
  67. {
  68.     if( (offset & 0x07) == 0x03 )
  69.     {
  70.         int changes = offset^last_addr;
  71.         /* A7 = data enable for VLM5030 (don't care )          */
  72.         /* A8 = STA pin (1->0 data data  , 0->1 start speech   */
  73.         /* A9 = RST pin 1=reset                                */
  74.  
  75.         /* A8 VLM5030 ST pin */
  76.         if( changes & 0x100 )
  77.             VLM5030_ST( offset&0x100 );
  78.         /* A9 VLM5030 RST pin */
  79.         if( changes & 0x200 )
  80.             VLM5030_RST( offset&0x200 );
  81.     }
  82.     last_addr = offset;
  83. }
  84.  
  85. READ_HANDLER( hyperspt_sh_timer_r )
  86. {
  87.     int clock = cpu_gettotalcycles() / TIMER_RATE;
  88.  
  89.     return (clock & 0x3) | (VLM5030_BSY()? 0x04 : 0);
  90. }
  91.  
  92. WRITE_HANDLER( hyperspt_sound_w )
  93. {
  94.     int changes = offset^last_addr;
  95.     /* A3 = data enable for VLM5030 (don't care )          */
  96.     /* A4 = STA pin (1->0 data data  , 0->1 start speech   */
  97.     /* A5 = RST pin 1=reset                                */
  98.     /* A6 = VLM5030    output disable (don't care ) */
  99.     /* A7 = kONAMI DAC output disable (don't care ) */
  100.     /* A8 = SN76489    output disable (don't care ) */
  101.  
  102.     /* A4 VLM5030 ST pin */
  103.     if( changes & 0x10 )
  104.         VLM5030_ST( offset&0x10 );
  105.     /* A5 VLM5030 RST pin */
  106.     if( changes & 0x20 )
  107.         VLM5030_RST( offset&0x20 );
  108.  
  109.     last_addr = offset;
  110. }
  111.  
  112.  
  113.  
  114. WRITE_HANDLER( konami_sh_irqtrigger_w )
  115. {
  116.     static int last;
  117.  
  118.     if (last == 0 && data)
  119.     {
  120.         /* setting bit 0 low then high triggers IRQ on the sound CPU */
  121.         cpu_cause_interrupt(1,0xff);
  122.     }
  123.  
  124.     last = data;
  125. }
  126.  
  127.  
  128. WRITE_HANDLER( konami_SN76496_latch_w )
  129. {
  130.     SN76496_latch = data;
  131. }
  132.  
  133.  
  134. WRITE_HANDLER( konami_SN76496_0_w )
  135. {
  136.     SN76496_0_w(offset, SN76496_latch);
  137. }
  138.  
  139.  
  140.  
  141.  
  142. READ_HANDLER( hyprolyb_speech_r )
  143. {
  144.     return ADPCM_playing(0) ? 0x10 : 0x00;
  145. }
  146.  
  147. WRITE_HANDLER( hyprolyb_ADPCM_data_w )
  148. {
  149.     int cmd,start,end;
  150.     unsigned char *RAM = memory_region(REGION_CPU3);
  151.  
  152.  
  153.     /* simulate the operation of the 6802 */
  154.     cmd = RAM[0xfe01 + data] + 256 * RAM[0xfe00 + data];
  155.     start = RAM[cmd + 1] + 256 * RAM[cmd];
  156.     end = RAM[cmd + 3] + 256 * RAM[cmd + 2];
  157.     if (end > start)
  158.         ADPCM_play(0,start,(end - start)*2);
  159. }
  160.